module.exports = option => {
    return async (req, res, next) => {
        const jwt = require('jsonwebtoken')
        const User = require('../models/User')
        const assert = require('http-assert')
        const secret = await require('fs').readFileSync('secret.text', 'utf-8')
        const token = (req.headers.authorization || '').split(' ').pop()
        assert(token, 201, '请先登录')
        const {
            id
        } = jwt.verify(token, secret)
        assert(id, 201, '请先登录')
        req.user = await User.findById(id)
        assert(req.user, 201, '请先登录')
        await next()
    }
}